// JavaScript Document

function CreateXMLHttpRequest()
{
	if (window.XMLHttpRequest )
	{
		return new XMLHttpRequest()
	}
	else if (window.ActiveXObject )
	{
		return new ActiveXObject("Microsoft.XMLHTTP")
	}
}

function PhanTrang(MaNguoiBan, page, loai)
{
	xmlHttp = CreateXMLHttpRequest();
	
	if (loai == 1)
	{
		xmlHttp.onreadystatechange = function()
		{
				if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
				{
					var kq = xmlHttp.responseText;
					document.getElementById("SuKienByMaNguoiBan").innerHTML = kq;
				}
		}
		
		var serverURL = "components/nguoiban/detail_sukien.php?MaNguoiBan="+MaNguoiBan+"&page="+page+"&ajax=1";
	}
	else
	{
		xmlHttp.onreadystatechange = function()
		{
				if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
				{
					var kq = xmlHttp.responseText;
					document.getElementById("SanPhamByMaNguoiBan").innerHTML = kq;
				}
		}
		
		var serverURL = "components/nguoiban/detail_sanpham.php?MaNguoiBan="+MaNguoiBan+"&page="+page+"&ajax=1";
	}

	
	serverURL += "&t" + new Date().getTime();
	
	xmlHttp.open("GET", serverURL, true);
	xmlHttp.send(null);
}

// ////////////////////////////// Tìm kiếm cơ bản ////////////////////////////////////////////////////////////////////////
function CapNhatHienThi()
{
	var TuKhoa = document.getElementById("txtTukhoa").value;
	var LoaiSort = document.getElementById("LoaiSort").value;

	xmlHttp = CreateXMLHttpRequest();
	
	xmlHttp.onreadystatechange = function()
	{
			if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
			{
				var kq = xmlHttp.responseText;
				
				document.getElementById("KetQuaTimKiem").innerHTML = kq;
			}
	}
	
	var serverURL = "components/sanpham/timkiemcoban_sanpham.php?TuKhoa="+TuKhoa+"&LoaiSort="+LoaiSort+"&ajax=1";

	serverURL += "&t" + new Date().getTime();
	
	xmlHttp.open("GET", serverURL, true);
	xmlHttp.send(null);
}

function TimKiemCoBan()
{
//	alert("aaa");
	var TuKhoa = document.getElementById("txtTukhoa").value;

	xmlHttp = CreateXMLHttpRequest();
	
	xmlHttp.onreadystatechange = function()
	{
			if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
			{
				var kq = xmlHttp.responseText;
				document.getElementById("KetQuaTimKiem").innerHTML = kq;
			}
	}
	
	var serverURL = "components/sanpham/timkiemcoban_sanpham.php?TuKhoa="+TuKhoa+"&ajax=1";

	serverURL += "&t" + new Date().getTime();
	
	xmlHttp.open("GET", serverURL, true);
	xmlHttp.send(null);
}

function PhanTrangTimKiemCoBan(TuKhoa, page, LoaiSort)
{
	xmlHttp = CreateXMLHttpRequest();

	xmlHttp.onreadystatechange = function()
	{
			if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
			{
				var kq = xmlHttp.responseText;
				document.getElementById("KetQuaTimKiem").innerHTML = kq;
			}
	}
	
	var serverURL = "components/sanpham/timkiemcoban_sanpham.php?TuKhoa="+TuKhoa+"&LoaiSort="+LoaiSort+"&page="+page+"&ajax=1";

	
	serverURL += "&t" + new Date().getTime();
	
	xmlHttp.open("GET", serverURL, true);
	xmlHttp.send(null);
}

// ////////////////////////////// Tìm kiếm nâng cao ////////////////////////////////////////////////////////////////////////
function CapNhatHienThiNangCao()
{
	var SanPham = document.getElementById("txtSanPham").value;
	var NguoiBan = document.getElementById("txtNguoiBan").value;
	var NhaSanXuat = document.getElementById("txtNhaSanXuat").value;
	var MoTa = document.getElementById("txtMoTa").value;
	var MaDanhMuc = document.getElementById("cbxDanhMuc").value;
	
	var LoaiSort = document.getElementById("LoaiSort").value;

	xmlHttp = CreateXMLHttpRequest();
	
	xmlHttp.onreadystatechange = function()
	{
			if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
			{
				var kq = xmlHttp.responseText;
				
				document.getElementById("KetQuaTimKiem").innerHTML = kq;
			}
	}
	
	var serverURL = "components/sanpham/timkiemnangcao_sanpham.php?SanPham="+SanPham+"&NguoiBan="+NguoiBan+"&NhaSanXuat="+NhaSanXuat+"&MoTa="+MoTa+"&MaDanhMuc="+MaDanhMuc+"&LoaiSort="+LoaiSort+"&ajax=1";

	serverURL += "&t" + new Date().getTime();
	
	xmlHttp.open("GET", serverURL, true);
	xmlHttp.send(null);
}

function TimKiemNangCao()
{
//	alert("aaa");
	var SanPham = document.getElementById("txtSanPham").value;
	var NguoiBan = document.getElementById("txtNguoiBan").value;
	var NhaSanXuat = document.getElementById("txtNhaSanXuat").value;
	var MoTa = document.getElementById("txtMoTa").value;
	var MaDanhMuc = document.getElementById("cbxDanhMuc").value;

	xmlHttp = CreateXMLHttpRequest();
	
	xmlHttp.onreadystatechange = function()
	{
			if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
			{
				var kq = xmlHttp.responseText;
				document.getElementById("KetQuaTimKiem").innerHTML = kq;
			}
	}
	
	var serverURL = "components/sanpham/timkiemnangcao_sanpham.php?SanPham="+SanPham+"&NguoiBan="+NguoiBan+"&NhaSanXuat="+NhaSanXuat+"&MoTa="+MoTa+"&MaDanhMuc="+MaDanhMuc+"&ajax=1";

	serverURL += "&t" + new Date().getTime();
	
	xmlHttp.open("GET", serverURL, true);
	xmlHttp.send(null);
}

function PhanTrangTimKiemNangCao(SanPham,NguoiBan,NhaSanXuat,MoTa,MaDanhMuc, page, LoaiSort)
{
	xmlHttp = CreateXMLHttpRequest();

	xmlHttp.onreadystatechange = function()
	{
			if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
			{
				var kq = xmlHttp.responseText;
				document.getElementById("KetQuaTimKiem").innerHTML = kq;
			}
	}
	
	var serverURL = "components/sanpham/timkiemnangcao_sanpham.php?SanPham="+SanPham+"&NguoiBan="+NguoiBan+"&NhaSanXuat="+NhaSanXuat+"&MoTa="+MoTa+"&MaDanhMuc="+MaDanhMuc+"&LoaiSort="+LoaiSort+"&page="+page+"&ajax=1";

	
	serverURL += "&t" + new Date().getTime();
	
	xmlHttp.open("GET", serverURL, true);
	xmlHttp.send(null);
}